package sipuser

import (
	"dmsv/models"
	"github.com/beego/beego/v2/core/logs"
)

type Acct struct {
	Account  string
	Password string
	Active   bool
}

var gUsers map[string]Acct

func GetUser(acct string) Acct {

	res, ok := gUsers[acct]
	if ok {
		return res
	}

	u, err := models.GetSipUser(acct)
	if err != nil {
		logs.Error("get user :%v err:%v", acct, err)
		return Acct{}
	}

	newUser := Acct{
		Active:   u.Active,
		Account:  u.Account,
		Password: u.Password,
	}

	gUsers[acct] = newUser
	return newUser
}

func Init() {
	gUsers = make(map[string]Acct)
}
